/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2013
 */

package com.gxuwz.byssxsys.action;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javacommon.util.extjs.ExtJsPageHelper;
import javacommon.util.extjs.ListRange;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.lang.StringUtils;

import cn.org.rapid_framework.generator.provider.java.model.JavaClass;
import cn.org.rapid_framework.generator.provider.java.model.JavaField;
import cn.org.rapid_framework.page.Page;
import cn.org.rapid_framework.page.PageRequest;

import com.gxuwz.byssxsys.model.SystemInfo;
import com.opensymphony.xwork2.Preparable;
import com.opensymphony.xwork2.ModelDriven;
import static javacommon.util.extjs.Struts2JsonHelper.*;

import java.util.*;

import javacommon.base.*;
import javacommon.util.*;

import cn.org.rapid_framework.util.*;
import cn.org.rapid_framework.web.util.*;
import cn.org.rapid_framework.page.*;
import cn.org.rapid_framework.page.impl.*;

import com.gxuwz.byssxsys.model.*;
import com.gxuwz.byssxsys.dao.*;
import com.gxuwz.byssxsys.service.*;
import com.gxuwz.byssxsys.vo.query.*;

/**
 * @author badqiu email:badqiu(a)gmail.com
 * @version 1.0
 * @since 1.0
 */

public class SystemInfoAction extends BaseStruts2Action implements Preparable,
		ModelDriven {
	// 默认多列排序,example: username desc,createTime asc
	protected static final String DEFAULT_SORT_COLUMNS = null;

	// forward paths
	protected static final String QUERY_JSP = "/pages/SystemInfo/query.jsp";
	protected static final String LIST_JSP = "/pages/SystemInfo/list.jsp";
	protected static final String CREATE_JSP = "/pages/SystemInfo/create.jsp";
	protected static final String EDIT_JSP = "/pages/SystemInfo/edit.jsp";
	protected static final String SHOW_JSP = "/pages/SystemInfo/show.jsp";
	// redirect paths,startWith: !
	protected static final String LIST_ACTION = "!/pages/SystemInfo/list.do";

	private SystemInfoManager systemInfoManager;

	private SystemInfo systemInfo;
	java.lang.Integer id = null;
	private String[] items;

	public void prepare() throws Exception {
		if (isNullOrEmptyString(id)) {
			systemInfo = new SystemInfo();
		} else {
			systemInfo = (SystemInfo) systemInfoManager.getById(id);
		}
	}

	/** 通过spring自动注入 */
	public void setSystemInfoManager(SystemInfoManager manager) {
		this.systemInfoManager = manager;
	}

	public Object getModel() {
		return systemInfo;
	}

	public void setId(java.lang.Integer val) {
		this.id = val;
	}

	public void setItems(String[] items) {
		this.items = items;
	}

	/**
	 * ExtGrid使用 列表
	 * 
	 * @throws IOException
	 */
	public void extlist() throws IOException {
		// PageRequest<Map> pr =
		// ExtJsPageHelper.createPageRequestForExtJs(getRequest(),
		// DEFAULT_SORT_COLUMNS);
		SystemInfoQuery pr = newQuery(SystemInfoQuery.class,
				DEFAULT_SORT_COLUMNS);
		Page page = systemInfoManager.findPage(pr);

		List<SystemInfo> SystemInfolist = (List) page.getResult();
		ListRange<SystemInfo> resultList = new ListRange<SystemInfo>();
		resultList.setList(SystemInfolist);
		resultList.setTotalSize(page.getTotalCount());
		resultList.setMessage("ok");
		resultList.setSuccess(true);
		outJson(resultList);
	}

	/**
	 * extGrid保存
	 * 
	 * @throws IOException
	 */
	public void extsave() throws IOException {
		Map<String, Object> result = new HashMap<String, Object>();
		try {
			systemInfoManager.save(systemInfo);
			result.put("success", true);
			result.put("msg", "添 加 成 功!");
		} catch (Exception e) {
			result.put("failure", true);
			result.put("msg", e.getMessage());
			e.printStackTrace();
		}
		outJson(result);
	}

	/**
	 * extGrid修改
	 * 
	 * @throws IOException
	 */
	public void extupdate() throws IOException {
		Map<String, Object> result = new HashMap<String, Object>();
		try {
			systemInfoManager.save(systemInfo);
			result.put("success", true);
			result.put("msg", "修 改 成 功!");
		} catch (Exception e) {
			result.put("failure", true);
			result.put("msg", e.getMessage());
			e.printStackTrace();
		}
		outJson(result);
	}

	/**
	 * extGrid删除
	 * 
	 * @throws IOException
	 */
	public void extdelete() throws IOException {
		String ids = getRequest().getParameter("ids");
		String[] idarray = ids.split(",");
		Map<String, Object> result = new HashMap<String, Object>();
		try {
			for (int i = 0; i < idarray.length; i++) {
				java.lang.Integer id = new java.lang.Integer(
						(String) idarray[i]);
				systemInfoManager.removeById(id);
			}
			result.put("success", true);
			result.put("msg", "删除成功");
		} catch (Exception e) {
			result.put("failure", true);
			result.put("msg", e.getMessage());
			e.printStackTrace();
		}
		outJson(result);
	}

}
